#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    File Name:      adb_screen_shot
    Author:         'daze'
    date:           2019/1/2
"""
import AutoWool.main.utils.dj_single_use_utils
import os

from AutoWool.main.config.config_utils import ConfigUtils
from AutoWool.main.utils.adb_utils import AdbUtils
from AutoWool.main.utils.log_utils import Log

if __name__ == "__main__":
    while True:
        result = input('请选择:\n ' +
                       '1.截取手机屏幕  \n ' +
                       '2.得到当前打开应用的包名和activity名  \n ' +
                       '3.根据包名和actvity名打开指定应用 \n ' +
                       '4.唤醒屏幕 \n ' +
                       '5.push 文件到手机 sdcard \n ' +
                       '6.pull 手机文件到电脑 \n ' +
                       '7.退出 \n ')
        if result == '1':
            template_img_abs_path = os.path.join(ConfigUtils.Dir.get_img_dir_abs_path(),
                                                 AdbUtils.phone_screen_shot_img_name)
            Log.log('开始截取手机屏幕,保存路径为:' + template_img_abs_path)
            AdbUtils.screen_cap_and_pull()
        elif result == '2':
            result_str = AdbUtils.get_cur_package_activity_name()
            Log.log('当前打开应用的包名和activity名为: ' + str(result_str))
        elif result == '3':
            Log.log('开始打开指定应用')
            package_activity_name = input('请输入步骤2得到的 包名和activity名: ')
            AdbUtils.open_target_app(package_activity_name)
        elif result == '4':
            Log.log('开始唤醒屏幕')
            AdbUtils.awake_screen()
        elif result == '5':
            Log.log('开始 push 文件到手机 ' + ConfigUtils.Dir.get_phone_video_save_path())
            video_path = input('请输入本地文件绝对路径:')
            AdbUtils.push_file_to_phone(video_path, ConfigUtils.Dir.get_phone_video_save_path())
            Log.log('push 完毕')
        elif result == '6':
            local_dir = input('请输入本地文件保存路径:')
            phone_file_abs_path = input('请输入手机 sdcard 文件的绝对路径:')
            tmp_phone_file_abs_path = 'storage/emulated/0/' + phone_file_abs_path
            Log.log('开始 pull 手机文件 ' + tmp_phone_file_abs_path + ' 到电脑 ' + local_dir)
            AdbUtils.pull_file_from_phone(local_dir, tmp_phone_file_abs_path)
            Log.log('pull 完毕')
        elif result == '7':
            Log.log('exit bye')
            break
